/**
 * 装饰者模式
 */

// 如打Dota，英雄升级时，在技能栏添加新的技能
class Hero {}

Hero.prototype.leaningSkills = () => {}

class Pugna extends Hero {
  constructor(name) {
    super()
    this.name = name
  }

  leaningSkills() {
    console.log(`${this.name} 学习了该技能`)
  }

}

// 装饰技能
class Skills extends Hero {
  constructor(hero) {
    super()
    this.hero = hero
  }

  learningSkills() {
    if(!this.hero) this.hero.learningSkills() 
  }

}

// 学习技能B
class SkillB extends Skills {
  constructor(hero, skillName) {
    super(hero)
    this.skillName = skillName
  }

  learningSkills() {
    console.log(`学习了技能B:${this.skillName}`)
    super.learningSkills()
  }

}
// 学习技能C
class SkillC extends Skills {
  constructor(hero, skillName) {
    super(hero)
    this.skillName = skillName
  }

  learningSkills() {
    console.log(`学习了技能C:${this.skillName}`)
    super.learningSkills()
  }

}

// 学习技能W
class SkillW extends Skills {
  constructor(hero, skillName) {
    super(hero)
    this.skillName = skillName
  }

  learningSkills() {
    console.log(`学习了技能W:${this.skillName}`)
    super.learningSkills()
  }

}


// 学习技能D
class SkillD extends Skills {
  constructor(hero, skillName) {
    super(hero)
    this.skillName = skillName
  }

  learningSkills() {
    console.log(`学习了技能D:${this.skillName}`)
    super.learningSkills()
  }

}

class Player {
  constructor(playName) {
    this.playName = playName
    this.hero = new Hero('湮灭法师')
    this.skills = new Skills(this.hero)
  }

  learningSkills(type) {
    switch(type) {
      case 'B':
        this.B = new SkillB(this.skills, '幽冥爆轰')
        break
      case 'C':
        this.C = new SkillC(this.skills, '衰老')
        break
      case 'W':
        this.W = new SkillW(this.skills, '幽冥守卫')
        break
      case 'D':
        this.D = new SkillD(this.skills, '生命汲取')
      default:
        this.B = new SkillB(this.skills, '幽冥爆轰')
        break
    }
  }

  useSkills(type) {
    switch(type) {
      case 'B':
        if(this.B) this.B.learningSkills()
        break
      case 'C':
        if(this.C) this.C.learningSkills()
        break
      case 'W':
        if(this.W) this.W.learningSkills()
        break
      case 'D':
        if(this.D) this.D.learningSkills()
        break
      default:
        console.log(this.playName + '没有释放技能。。。。')
        break
    }
  }


}

const player = new Player('水是你巴巴')

player.learningSkills('B')
player.learningSkills('C')
player.learningSkills('W')
player.learningSkills('D')

player.useSkills('B')
player.useSkills('C')
player.useSkills('W')
player.useSkills('D')

player.useSkills()
